<template>
  <div class="dialog-form">
    <el-form ref="PlatCodeManagementRef" :model="form" label-width="100px">
      <el-row :gutter="36">
        <el-col :span="12">
          <el-form-item label="码方案名称：">
            <p>{{ form.codeName }}</p>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="码方案code：">
            <p>{{ form.codeLabel }}</p>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="码类别：">
            <dict-tag :options="bus_qr_code_type" :value="form.codeType" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="码标准：">
            <dict-tag :options="bus_qr_code_standard" :value="form.codeStandard" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发码机构：">
            <p>{{ form.codeOrgan }}</p>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="公钥证书：">
            <p>{{ getCaName(form.caId) }}</p>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="码方案描述：">
        <p>{{ form.remark }}</p>
      </el-form-item>
      <el-form-item label="码方案示例："></el-form-item>
      <img src="../../../assets/images/code.png" class="img" />
    </el-form>
    <div class="dialog-footer">
      <el-button @click="onCancel">关闭</el-button>
    </div>
  </div>
</template>

<script setup>
import { getPlatCodeManagement, addPlatCodeManagement, updatePlatCodeManagement } from "@/api/bus/PlatCodeManagement"
import { getCaList } from '@/api/bus/certificateManagement'

const { proxy } = getCurrentInstance()
const { bus_qr_code_type,bus_enabled,bus_qr_code_standard } = proxy.useDict('bus_qr_code_type','bus_enabled','bus_qr_code_standard')

const emits = defineEmits(['cancel', 'confirm'])

const caList = ref([])
const PlatCodeManagementRef = ref()
const form = ref({
  id: null,
  caId: null,
  codeName: null,
  codeLabel: null,
  codeType: null,
  codeStandard: null,
  codeOrgan: null,
  enabled: '1',
  codeFlag: null,
  createBy: null,
  createTime: null,
  updateBy: null,
  updateTime: null
})

const pageInit = (id) => {
  getCaList().then((response) => {
		caList.value = response.data || []
	})
  if (id) {
    getPlatCodeManagement(id).then(response => {
      form.value = response.data
      form.value.enabled = form.value.enabled.toString()
    })
  }
}

const getCaName = (caId) => {
  const obj = caList.value.find(item => {
    return item.id == caId
  })
  return obj ? obj.requestNum : ''
}

const onCancel = () => {
  emits('cancel')
}

defineExpose({
  pageInit
})

</script>

<style lang="scss" scoped>
.img {
  width: 96%;
  margin-left: 2%;
  object-fit: contain;
}
</style>